package com.pengshun;

//import com.pengshun.utils.SpringContextHolder;

import com.pengshun.modules.common.SpringContextHolder;
import io.swagger.annotations.Api;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.MultipartConfigElement;


@EnableAsync
@EnableFeignClients
@RestController
@Api(hidden = true)
@SpringBootApplication(scanBasePackages = {"com.pengshun"})
@EnableTransactionManagement
//@EnableJpaAuditing(auditorAwareRef = "auditorAware")
@MapperScan(basePackages = {"com.pengshun.modules.api.mapper"})
public class ApiRunApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiRunApplication.class, args);
    }

    @Bean
    public SpringContextHolder springContextHolder() {
        return new SpringContextHolder();
    }

    @Bean
    public ServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory fa = new TomcatServletWebServerFactory();
        fa.addConnectorCustomizers(connector -> connector.setProperty("relaxedQueryChars", "[]{}"));
        return fa;
    }

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //  单个数据大小
        factory.setMaxFileSize("200MB"); // KB,MB
        /// 总上传数据大小
        factory.setMaxRequestSize("200MB");
        return factory.createMultipartConfig();
    }
}
